package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.TextArea;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import model.User;
import net.miginfocom.swing.MigLayout;

public class HighScoreTable extends JFrame {

	private JPanel contentPane;

	public HighScoreTable(User[] users) {
		super("High score table");
		
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new MigLayout("", "", ""));
		
		TextArea textArea = new TextArea();
		textArea.setEditable(false);
		contentPane.add(textArea, "cell 0 1,grow");
		
		Label label = new Label("High score");
		contentPane.add(label, "cell 0 0,alignx center,aligny center");
		for(int i=0; i<users.length; i++)
			textArea.append(i+1 +". "+users[i].toString() + "\n");
		addWindowListener(new FrameHandler());
		setVisible(true);
		pack();
	}
	private class FrameHandler extends WindowAdapter {
		public void windowClosing(WindowEvent event) {
			setVisible(false);
		}
	}
}
